
const reverse = (x) => {
    let res = 0;
    while (x !== 0) {
        const digit = x % 10;
        x = ~~(x / 10)
        res = res * 10 + digit
    }
    if (res > Math.pow(2, 31) - 1 || res < Math.pow(-2, 31)) {
        res = 0
    }
    return res
}
console.log(reverse(-121));
console.log(reverse(12447));